package org.apache.commons.logging;

import com.stars.easyms.logger.support.commons.logging.EasyMsCommonsLog;
import org.slf4j.LoggerFactory;

/**
 * <p>className: LogFactory</p>
 * <p>description: 替换原生的LogFactory，使其支持easy-ms-logger</p>
 *
 * @author guoguifang
 * @date 2019-11-12 18:37
 * @since 1.3.3
 */
public abstract class LogFactory {

    /**
     * Convenience method to return a named logger.
     *
     * @param clazz containing Class from which a log name will be derived
     */
    public static Log getLog(Class<?> clazz) {
        return new EasyMsCommonsLog(LoggerFactory.getLogger(clazz));
    }

    /**
     * Convenience method to return a named logger.
     *
     * @param name logical name of the <code>EasyMsCommonsLog</code> instance to be returned
     */
    public static Log getLog(String name) {
        return new EasyMsCommonsLog(LoggerFactory.getLogger(name));
    }


    /**
     * This method only exists for compatibility with unusual Commons Logging API
     * usage like e.g. {@code LogFactory.getFactory().getInstance(Class/String)}.
     *
     * @see #getInstance(Class)
     * @see #getInstance(String)
     * @deprecated in favor of {@link #getLog(Class)}/{@link #getLog(String)}
     */
    @Deprecated
    public static LogFactory getFactory() {
        return new LogFactory() {};
    }

    /**
     * Convenience method to return a named logger.
     * <p>This variant just dispatches straight to {@link #getLog(Class)}.
     *
     * @param clazz containing Class from which a log name will be derived
     * @deprecated in favor of {@link #getLog(Class)}
     */
    @Deprecated
    public Log getInstance(Class<?> clazz) {
        return getLog(clazz);
    }

    /**
     * Convenience method to return a named logger.
     * <p>This variant just dispatches straight to {@link #getLog(String)}.
     *
     * @param name logical name of the <code>Log</code> instance to be returned
     * @deprecated in favor of {@link #getLog(String)}
     */
    @Deprecated
    public Log getInstance(String name) {
        return getLog(name);
    }
}